package com.taikang.hmp.hbusiness.diabetes.measure.weight.action.view;

import java.util.List;

import net.sf.json.JSONObject;

import org.apache.commons.lang.NumberUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.ServletActionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.taikang.hmp.frame.common.TKException;
import com.taikang.hmp.frame.common.datastructre.Dto;
import com.taikang.hmp.frame.common.datastructre.support.BaseDto;
import com.taikang.hmp.frame.common.datastructre.support.ResponseDto;
import com.taikang.hmp.frame.common.web.action.BaseAction;
import com.taikang.hmp.hbusiness.diabetes.measure.weight.bean.Weight;
import com.taikang.hmp.hbusiness.diabetes.measure.weight.service.IWeightService;

/** 
 * 体重
 * author:wyf
 * time:2015年8月5日 上午11:02:42
 */
public class WeightViewAction extends BaseAction{
	private static Logger logger = LoggerFactory.getLogger(WeightViewAction.class);
	
	private IWeightService weightService;
	

	public IWeightService getWeightService() {
		return weightService;
	}

	public void setWeightService(IWeightService weightService) {
		this.weightService = weightService;
	}



	public String executeAction() {
		// 显示体重折线图
		if ("showWeightChart".equals(requestDto.getMethod())) {
			return showWeightChart();
		}  else {
			throw new TKException("no support method:"+requestDto.getMethod());
		}
	}

	/**
	 * 显示体重折线图
	 * 
	 * @return
	 */
	public String showWeightChart()  {
		logger.info("进入showWeightChart方法体:"+requestDto.toString());
		//通用校验
		ResponseDto responseDto = new ResponseDto();			
		//获取参数
		Dto paramDto = requestDto.getRequestlist().get(0);
		paramDto = super.appendRequestBase(paramDto, requestDto);
		
		
		String height = weightService.getHeight(paramDto);
		List<Weight> weightlist = weightService.getWeightChartList(paramDto);
		
		//计算BMI
		if(weightlist!=null){
			for(Weight rtnweight : weightlist){
				////+ (Number(wi.value) / (height * height)).toFixed(1)
				if(StringUtils.isNotEmpty(rtnweight.getValue()) && NumberUtils.isNumber(rtnweight.getValue())){
					
				}
				rtnweight.setBmi("");
			}
		}

		Dto dto = new BaseDto();
		dto.put("records", weightlist);
		dto.put("height", height);
		responseDto.pushResultDto(dto);
		super.setDataMap(responseDto);
		//dataMap.put("resultMsg", "success");
		return SUCCESS;
	}

}
